package com.dd.ent.car.ui.user.note;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.TextView;

import com.dd.ent.car.R;
import com.dd.ent.car.common.config.UIConfig;
import com.dd.ent.car.ui.BaseActivity;
import com.pp.ent.core.manage.UIHandler;
import com.pp.ent.view.annotation.ContentView;
import com.pp.ent.view.annotation.OnClick;
import com.pp.ent.view.annotation.ViewInject;


/**
 * Created by dengqu on 2017/4/6.
 */
@ContentView(R.layout.activity_user_note)
public class UserNoteActivity extends BaseActivity {
    public final static String TYPE="type";
    @ViewInject(R.id.titlebar_title)
    private TextView titleBar;

    private Type type = Type.NETWORK;
    private UserNoteFragment userNoteFragment;

    public enum Type{
        NETWORK,
        DRAFT
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        handleIntent();
        init();
        setDefaultFragment();
    }

    private void handleIntent() {
        type = (Type) getIntent().getSerializableExtra(TYPE);
    }

    private void init() {
        titleBar.setText("我发表的");
    }

    public static void startSelf(Context context,Type type) {
        Intent intent = new Intent(context, UserNoteActivity.class);
        intent.putExtra(TYPE,type);
        context.startActivity(intent);
    }

    private void setDefaultFragment() {
        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();
        if (userNoteFragment==null) {
            userNoteFragment = UserNoteFragment.getInstance(type);
        }
        transaction.replace(R.id.fra_container, userNoteFragment);
        transaction.commit();
    }

    @OnClick({R.id.titlebar_left})
    public void onnClick(View view) {
        switch (view.getId()) {
            case R.id.titlebar_left:
                finish();
                break;
        }
    }

    @UIHandler(UIConfig.ADD_NOTE_INFO_TO_SERVER_SUCCESS)
    public void addNoteInfoServerSuccessResponse() {
        finish();
    }
}
